﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KylinORM.CQRS.Subscriber;
using KylinORM.CQRS.Publisher;

namespace KylinORM.CQRS
{
    /// <summary>
    /// 定义一个消息端点
    /// </summary>
    public interface IEndpoint
    {
        /// <summary>
        /// 注册消息响应
        /// </summary>
        /// <param name="messageName">消息名称</param>
        /// <param name="callbackFunc">消息响应的回调方法</param>
        void On(string messageName, Delegate callbackFunc);
        /// <summary>
        /// 注册消息响应
        /// </summary>
        /// <param name="messageName">消息名称</param>
        /// <param name="callbackFunc">消息响应的回调方法</param>
        /// <param name="messageType">消息响应的类型</param>
        void On(string messageName, Delegate callbackFunc, EMessageType messageType);
        /// <summary>
        /// 注册消息响应
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="messageName">消息名称</param>
        /// <param name="callbackFunc">消息响应的回调方法</param>
        void On<T>(string messageName, Action<T> callbackFunc) where T : IMessage;
        /// <summary>
        /// 注册消息响应
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="messageName">消息名称</param>
        /// <param name="callbackFunc">消息响应的回调方法</param>
        /// <param name="messageType">消息响应的类型</param>
        void On<T>(string messageName, Action<T> callbackFunc, EMessageType messageType) where T : IMessage;
        /// <summary>
        /// 注册消息响应
        /// </summary>
        /// <param name="messageName">消息名称</param>
        /// <param name="messageHandler">消息响应</param>
        void On(string messageName, MessageHandler messageHandler);

        /// <summary>
        /// 将消息发送到已注册的响应程序
        /// </summary>
        /// <param name="message">消息对象</param>
        void Send(IMessage message);

        /// <summary>
        /// 得到已注册的消息响应
        /// </summary>
        /// <param name="messageName"></param>
        /// <returns></returns>
        List<MessageHandler> GetHandlers(string messageName);

        /// <summary>
        /// 是否已注指定的消息响应
        /// </summary>
        /// <param name="messageName"></param>
        /// <returns></returns>
        bool HasHandler(string messageName);

        /// <summary>
        /// 消息端点地址，格式object://命名空间/类名/属性名
        /// </summary>
        Uri Url { get; set; }

    }
}
